import requests
import re
import json
import matplotlib.pyplot as plt



url = "https://3g.dxy.cn/newh5/view/pneumonia?scene=2&clicktime=1579582238&enterid=1579582238&from=timeline&isappinstalled=0"

# 爬取数据 
def get_data_dict():
    r = requests.get(url)
    r.encoding = 'utf-8'
    r = r.text

    # 处理数据
    m = re.findall(' window\.getAreaStat = (.*?)\}catch',r)
    # 原始字典
    province_dict = eval(m[0])

    print('有%d个省'%len(province_dict))
    

    # 人数
    num = []
    # 省份
    province = []
    for i in range(len(province_dict)):
        num.append(province_dict[i]['confirmedCount'])
        province.append(province_dict[i]['provinceName'])

    print(num)
    print(province)
    return num, province, province_dict




if __name__ == "__main__":
    pass